home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / debugger / ddd-1.000 / ddd-1 / ddd-1.4b / ddd / Box.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-21  |  4.7 KB  |  211 lines

  1. // $Id: Box.C,v 1.6 1995/11/21 13:49:07 zeller Exp $
  2. // Klasse Box (Implementation)
  3.  
  4. // Copyright (C) 1995 Technische Universitaet Braunschweig, Germany.
  5. // Written by Andreas Zeller (zeller@ips.cs.tu-bs.de).
  6. // 
  7. // This file is part of the DDD Library.
  8. // 
  9. // The DDD Library is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU Library General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. // 
  14. // The DDD Library is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. // See the GNU Library General Public License for more details.
  18. // 
  19. // You should have received a copy of the GNU Library General Public
  20. // License along with the DDD Library -- see the file COPYING.LIB.
  21. // If not, write to the Free Software Foundation, Inc.,
  22. // 675 Mass Ave, Cambridge, MA 02139, USA.
  23. // 
  24. // DDD is the data display debugger.
  25. // For details, see the DDD World-Wide-Web page, 
  26. // `http://www.cs.tu-bs.de/softech/ddd/',
  27. // or send a mail to the DDD developers at `ddd@ips.cs.tu-bs.de'.
  28.  
  29. #ifdef __GNUG__
  30. #pragma implementation
  31. #endif
  32.  
  33. char Box_rcsid[] = 
  34.     "$Id: Box.C,v 1.6 1995/11/21 13:49:07 zeller Exp $";
  35.  
  36. #include <string.h>
  37.  
  38. #include "assert.h"
  39. #include "return.h"
  40. #include <X11/X.h>
  41. #include <X11/Xlib.h>
  42. #include <X11/Intrinsic.h>
  43.  
  44. #include "Box.h"
  45. #include "TagBox.h"
  46. #include "VSEFlags.h"
  47.  
  48. DEFINE_TYPE_INFO_0(Box)
  49. DEFINE_TYPE_INFO_0(BoxPrintGC)
  50. DEFINE_TYPE_INFO_1(BoxPostScriptGC, BoxPrintGC)
  51. DEFINE_TYPE_INFO_1(BoxFigGC, BoxPrintGC)
  52.  
  53.  
  54. // Anzeigen
  55.  
  56. // Box anzeigen
  57. void Box::draw(Widget w, 
  58.            const BoxRegion& r, 
  59.            const BoxRegion& exposed, 
  60.            GC gc, 
  61.            bool context_selected) const
  62. {
  63.     // Wenn nicht im exponierten Bereich, dann Abbruch
  64.     if (!(r <= exposed))
  65.     return;
  66.  
  67.     if (VSEFlag(show_draw))
  68.     cout << "\n[" << r;
  69.  
  70.     // Sicherstellen, dass genug Platz vorhanden
  71.     assert(!(size() > r.space()));
  72.  
  73.     // Grafik-Kontext auf Default setzen
  74.     if (gc == 0)
  75.     gc = DefaultGCOfScreen(XtScreen(w));
  76.  
  77.     // Eigentliche Anzeigefunktion aufrufen
  78.     _draw(w, r, exposed, gc, context_selected);
  79.  
  80.     if (VSEFlag(show_draw))
  81.     cout << "]";
  82. }
  83.  
  84.  
  85. // Vergleichen
  86.  
  87. // Boxen vergleichen (intern)
  88. bool Box::matches(const Box &b, const Box *) const
  89. {
  90.     return (size() == b.size() &&
  91.     extend() == b.extend() &&
  92.     strcmp(type(), b.type()) == 0);
  93. }
  94.  
  95.  
  96. // Boxen vergleichen (oeffentliche Schnittstelle)
  97. bool Box::operator == (const Box &b) const
  98. {
  99.     if (VSEFlag(show_match_boxes))
  100.     {
  101.     cout << "\nBox match: " << *this << " ? " << b;
  102.     cout.flush();
  103.     }
  104.  
  105.     bool flag = (this == &b) || matchMe().matches(b.matchMe(), &b);
  106.  
  107.     if (VSEFlag(show_match_boxes))
  108.     {
  109.     if (flag)
  110.         cout << "\nBox match: " << *this << " == " << b;
  111.     else
  112.         cout << "\nBox match: " << *this << " != " << b;
  113.  
  114.     cout.flush();
  115.     }
  116.     
  117.     return flag;
  118. }
  119.  
  120.  
  121. // Markierungen
  122.  
  123. // Box markieren
  124. Box *Box::tag(Data *dta, DataLink *dl)
  125. {
  126.     TagBox *ret = new TagBox(this, dta, dl);
  127.     unlink();
  128.     return ret;
  129. }
  130.  
  131. // BoxRegion der TagBox zu Punkt p zurueckgeben (kein Punkt: oberste)
  132. BoxRegion Box::region(BoxPoint p) const RETURNS(r)
  133. {
  134.     RETURN_OBJECT(BoxRegion, r);
  135.     const TagBox *t = findTag(p);
  136.     if (t)
  137.     r = t->__region();
  138.     else
  139.     r = BoxRegion(BoxPoint(0,0), BoxSize(0,0));
  140.     RETURN(r);
  141. }
  142.  
  143. // Datum der TagBox zu Punkt p zurueckgeben (kein Punkt: oberste)
  144. Data *Box::data(BoxPoint p) const
  145. {
  146.     const TagBox *t = findTag(p);
  147.     if (t == 0)
  148.     return 0;
  149.     return t->__data();
  150. }
  151.  
  152. // Namen der TagBox zu Punkt p zurueckgeben (kein Punkt: oberste)
  153. string Box::name(BoxPoint p) const RETURNS(name)
  154. {
  155.     RETURN_OBJECT(string, name);
  156.     const TagBox *t = findTag(p);
  157.     if (t)
  158.     name = t->__name();
  159.     else
  160.     name = "";
  161.     RETURN(name);
  162. }
  163.  
  164. // Information der TagBox zu Punkt p zurueckgeben (kein Punkt: oberste)
  165. string Box::info(BoxPoint p) const RETURNS(info)
  166. {
  167.     RETURN_OBJECT(string, info);
  168.     const TagBox *t = findTag(p);
  169.     if (t)
  170.     info = t->__info();
  171.     else
  172.     info = "";
  173.     RETURN(info);
  174. }
  175.  
  176. // Ausgewaehlt-Eigenschaft der TagBox zu Punkt p zurueckgeben
  177. bool Box::selected(BoxPoint p) const
  178. {
  179.     const TagBox *t = findTag(p);
  180.     if (t == 0)
  181.     return false;
  182.     return t->__selected();
  183. }
  184.  
  185.  
  186. // Debugging
  187.  
  188. // Box ausgeben
  189. ostream &operator << (ostream& s, const Box& b)
  190. {
  191.     if (VSEFlags::max_info_nesting != 0)
  192.     {
  193.     VSEFlags::max_info_nesting--;
  194.  
  195.     b.dump(s);
  196.  
  197.     if (VSEFlags::include_id_info)
  198.         s << " (id: " << b.id() << ")";
  199.  
  200.     if (VSEFlags::include_size_info)
  201.         s << " // size = " << b.size() << " corner = " << b.corner() <<
  202.         " extend = " << b.extend() << "\n";
  203.  
  204.     VSEFlags::max_info_nesting++;
  205.     }
  206.     else
  207.     s << "_";
  208.  
  209.     return s;
  210. }
  211.